package com.github.laozhaishaozuo.asm;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;

import org.apache.commons.codec.binary.Hex;

public class HelloClassFile {

	public static final String TEST_FILE_PATH = "/asm/HelloWorld.clazz";

	public static void main(String[] args) {
		String classpath = HelloClassFile.class.getResource("/").getPath();
		System.out.println(classpath);
		File file = new File(classpath, TEST_FILE_PATH);
		System.out.println(file.getAbsolutePath());

		if (file.exists()) {
			int dataLength = 0;
			byte[] buffer = new byte[1024];
			try (DataInputStream dis = new DataInputStream(new FileInputStream(file));) {
				dataLength = dis.available();
				dis.read(buffer, 0, 4);
				byte[] magic = Arrays.copyOf(buffer, 4);
				System.out.println(Hex.encodeHexString(magic));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
